FROM osrf/ros:melodic-desktop-full

# build参数
ARG user=docker
ARG password=docker

# 元数据
LABEL maintainer="jiejie" 
LABEL email="jiejietop@gmail.com"
LABEL org.label-schema.schema-version="1.0"
LABEL org.label-schema.build-date="2022-04"
LABEL org.label-schema.name="rs:u18-ros"
LABEL org.label-schema.description="Ubuntu 18 and ros-melodic image"
LABEL org.label-schema.docker.cmd="\
docker run \
-it \
--privileged \
-v [host path]:[work path] \
-p [docker port-port]:[docker port-port] \
-d rs:u18-ros \
"

USER root

# tuna.tsinghua.edu.cn
# aliyun.com
RUN  sed -i s@/archive.ubuntu.com/@/mirrors.tuna.tsinghua.edu.cn/@g /etc/apt/sources.list \
    && sed -i s@/security.ubuntu.com/@/mirrors.tuna.tsinghua.edu.cn/@g /etc/apt/sources.list \
    && apt-get update --fix-missing && apt-get upgrade -y

# Setup environment
RUN apt-get install -y locales apt-utils sudo

RUN locale-gen zh_CN.UTF-8
ENV \
    LANG=zh_CN.UTF-8 \
    DEBIAN_FRONTEND=noninteractive \
    TERM=xterm

# 设置时区为上海
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

# 添加用户：赋予sudo权限，指定密码
RUN useradd --create-home --no-log-init --shell /bin/bash ${user} \
    && adduser ${user} sudo \
    && echo "${user}:${password}" | chpasswd

# 指定容器起来的工作目录
WORKDIR /home/${user}

RUN apt-get remove -y --purge xserver-xorg

RUN apt-get install --no-install-recommends -y \
    gnupg2 \
    mesa-utils \
    sudo \
    tmux \
    wget \
    curl \
    apt-file \
    xserver-xorg

RUN dpkg-reconfigure xserver-xorg

# Install dependencies
# https://unix.stackexchange.com/a/391112
RUN apt-get install -y \
    ros-melodic-amcl \
    ros-melodic-base-local-planner \
    ros-melodic-costmap-2d \
    ros-melodic-depth-image-proc \
    ros-melodic-depthimage-to-laserscan \
    ros-melodic-dynamixel-workbench-toolbox \
    ros-melodic-four-wheel-steering-msgs \
    ros-melodic-geographic-msgs \
    ros-melodic-gmapping \
    ros-melodic-image-proc \
    ros-melodic-joint-state-publisher-gui \
    ros-melodic-joy \
    ros-melodic-map-server \
    ros-melodic-mavros-msgs \
    ros-melodic-move-base \
    ros-melodic-moveit \
    ros-melodic-moveit-commander \
    ros-melodic-moveit-python \
    ros-melodic-moveit-visual-tools \
    ros-melodic-navfn \
    ros-melodic-open-manipulator-msgs \
    ros-melodic-pcl-ros \
    ros-melodic-pluginlib \
    ros-melodic-rgbd-launch \
    ros-melodic-robot-calibration \
    ros-melodic-robot-controllers \
    ros-melodic-robot-localization \
    ros-melodic-ros-control \
    ros-melodic-ros-controllers \
    ros-melodic-rosparam-shortcuts \
    ros-melodic-rosserial-python \
    ros-melodic-rotate-recovery \
    ros-melodic-serial \
    ros-melodic-slam-karto \
    ros-melodic-teb-local-planner \
    ros-melodic-teleop-twist-keyboard \
    ros-melodic-tf2-geometry-msgs \
    ros-melodic-twist-mux \
    ros-melodic-urdf-geometry-parser \
    ros-melodic-voxel-grid \
    ros-melodic-jsk-visualization \
    libspdlog-dev \
    libjsoncpp-dev \
    libeigen3-dev \
    libzmq3-dev \
    libusb-1.0.0-dev \
    mesa-common-dev \
    build-essential \
    libgl1-mesa-dev \
    libpqxx-dev \
    zsh \
    git \
    g++ \
    dbus \
    tree \
    openssl \
    systemd \
    tshark \
    net-tools \
    wireshark \
    iputils-ping \
    tmux \
    libopencv-dev \
    vim

# ==================

# ########################## 安装Ubuntu中文字体支持 ################################
RUN git clone https://gitee.com/jiejietop/ubuntu-fonts.git /tmp/ubuntu-fonts
RUN cp -rdf /tmp/ubuntu-fonts/usr/share/fonts/my-ubuntu-fonts /usr/share/fonts/.


# ########################## zsh环境配置 ################################
RUN chsh -s /bin/zsh
RUN usermod -s /bin/zsh ${user}

USER ${user}
RUN git clone https://gitee.com/jiejieTop/ohmyzsh.git /home/${user}/.oh-my-zsh
RUN git clone https://gitee.com/jiejieTop/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-/home/${user}/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
RUN git clone https://gitee.com/jiejieTop/zsh-autosuggestions.git ${ZSH_CUSTOM:-/home/${user}/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
RUN git clone https://gitee.com/jiejieTop/git-open.git ${ZSH_CUSTOM:-/home/${user}/.oh-my-zsh/custom}/plugins/git-open
RUN cp /home/${user}/.oh-my-zsh/templates/zshrc.zsh-template /home/${user}/.zshrc
RUN sed -i 's/plugins=(git)/plugins=(z git sudo extract vi-mode git-open safe-paste command-not-found colored-man-pages zsh-syntax-highlighting vscode zsh-autosuggestions)/g' /home/${user}/.zshrc \
    && sed -i 's/# DISABLE_AUTO_UPDATE="true"/DISABLE_AUTO_UPDATE="true"/g' /home/${user}/.zshrc

RUN echo "source /opt/ros/melodic/setup.bash" >> /home/${user}/.bashrc
RUN echo "source /opt/ros/melodic/setup.zsh" >> /home/${user}/.zshrc


USER ${user}
